import React from "react"
import ReactDOM from "react-dom"
import classNames from 'classnames'
require('./FormView.less')

class FormView extends React.Component {
    constructor(props) {
        super(props)
        this.state = {
        }
    }
    row(data, last) {
        //如果没有快递单号
        if(data.label === null){
            return null
        }
        return (
            <div className="FormView-row" key={data.label}>
                <div className = {classNames("label",data.className)}>
                    {data.label}
                </div>
                <div className = {classNames("span",data.className)}>
                    {data.span}
                </div>
            </div>
        )
    }

    componentWillMount(){
        const data = this.props.dataSource || []
        const form_data = data.map(item=> this.row(item))
        this.setState({
            form_data: form_data
        })
    }

    render() {
        const data = this.props.dataSource || []
        const form_data = data.map(item=> this.row(item))
        if(data.length === 0){
            return null
        }else {
            return (
                <div className="FormView">
                    {form_data}
                </div>
            )
        }
    }
}

module.exports = FormView